import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_hx/services/app_theme_services.dart';
import 'package:get/get.dart';

import 'login_logic.dart';

class LoginPage extends GetView<LoginLogic> {
  const LoginPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration:const BoxDecoration(
          image: DecorationImage(
              image: AssetImage("assets/images/login_bg.png"),
              fit:BoxFit.fill
          ),
          color: Colors.white
      ),
      child:GetBuilder<LoginLogic>(
        builder: (logic)=>Scaffold(
          backgroundColor: Colors.transparent,
          appBar: AppBar(
            elevation: 0,
            actions: [
              controller.pageIndex==1?TextButton(
                  onPressed:()=>{},
                  child: Text("已有账号？",style: AppThemeServices.textTheme.h13.copyWith(color: AppThemeServices.appColors.primarilyTextColor))):const SizedBox()
            ],
            backgroundColor: Colors.transparent,
            leading:GestureDetector(
              onTap: (){
                if(controller.pageIndex!=0){
                  controller.pageIndex=controller.pageIndex-1;
                }else{
                  Get.back();
                }
              },
              behavior: HitTestBehavior.opaque,
              child:Image.asset("assets/images/arrow-left.png"),
            ),
          ),
          body:Padding(
            padding: const EdgeInsets.only(top: 43,left: 15,right: 15),
            child:  controller.pageIndex==0?_createLoginView():(
                controller.pageIndex==1?_createRegisterView():const SizedBox()
            ),
          ),
        )
      ),
    );
  }

  Widget _createLoginView(){
    return SingleChildScrollView(child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("手机快捷登录",style: AppThemeServices.textTheme.h24.bold().copyWith(color: Colors.black)),
        const SizedBox(height: 105),
        TextField(
          onChanged: (v)=>controller.loginPhone=v,
          style: AppThemeServices.textTheme.h15.copyWith(color: Colors.black),
          decoration: InputDecoration(
              hintText: "请输入手机号",
              border: InputBorder.none,
              hintStyle:AppThemeServices.textTheme.h15.copyWith(color: AppThemeServices.appColors.hintTextColor)
          ),
        ),
        Divider(color: AppThemeServices.appColors.divider),
        TextField(
          onChanged: (v)=>controller.loginPassword=v,
          style: AppThemeServices.textTheme.h15.copyWith(color: Colors.black),
          obscureText: true,
          decoration: InputDecoration(
              hintText: "请输入密码",
              border: InputBorder.none,
              hintStyle:AppThemeServices.textTheme.h15.copyWith(color:const Color.fromRGBO(150, 151, 153, 1))
          ),
        ),
        Divider(color: AppThemeServices.appColors.divider),
        const SizedBox(height: 62),
        SizedBox(width: double.infinity,child: ElevatedButton(
            onPressed:controller.isLoginButtonClick?()=>controller.doLogin():null,
            style: ElevatedButton.styleFrom(
                primary: AppThemeServices.appColors.colorPrimary,
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(45)),
                shadowColor: Colors.transparent,
                fixedSize: const Size(double.infinity, 43)
            ),
            child: Text("登录",style: AppThemeServices.textTheme.h15.copyWith(color: Colors.white)))),
        const SizedBox(height: 15),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            TextButton(
                style: TextButton.styleFrom(
                ),
                onPressed: ()=>controller.pageIndex=1,
                child: Text("新用户注册",style: AppThemeServices.textTheme.h13.copyWith(color:const Color.fromRGBO(0, 195, 179, 1)))),
            const SizedBox(width: 22),
            Container(width: 1,height: 15,color: const Color.fromRGBO(0, 195, 179, 1)),
            const SizedBox(width: 22),
            TextButton(
                style: TextButton.styleFrom(
                ),
                onPressed: ()=>{},
                child: Text("忘记密码",style: AppThemeServices.textTheme.h13.copyWith(color:const Color.fromRGBO(0, 195, 179, 1))))
          ],
        )
      ],
    ));
  }

  Widget _createRegisterView(){
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("手机快捷登录",style: AppThemeServices.textTheme.h24.bold().copyWith(color: Colors.black)),
        const SizedBox(height: 20),
        Expanded(child: SingleChildScrollView(
          child: Column(
            children: [
              TextField(
                onChanged: (v)=>controller.rgsPhone=v,
                style: AppThemeServices.textTheme.h15.copyWith(color: Colors.black),
                decoration: InputDecoration(
                    hintText: "请输入手机号",
                    border: InputBorder.none,
                    hintStyle:AppThemeServices.textTheme.h15.copyWith(color:AppThemeServices.appColors.hintTextColor)
                ),
              ),
              Divider(color: AppThemeServices.appColors.divider),
              TextField(
                onChanged: (v)=>controller.rgsSmsCode=v,
                style: AppThemeServices.textTheme.h15.copyWith(color: Colors.black),
                decoration: InputDecoration(
                    hintText: "请输入手机号",
                    border: InputBorder.none,
                    hintStyle:AppThemeServices.textTheme.h15.copyWith(color:AppThemeServices.appColors.hintTextColor)
                ),
              ),
              Divider(color: AppThemeServices.appColors.divider),
              TextField(
                onChanged: (v)=>controller.rgsPassword=v,
                style: AppThemeServices.textTheme.h15.copyWith(color: Colors.black),
                decoration: InputDecoration(
                    hintText: "请输入登录密码",
                    border: InputBorder.none,
                    hintStyle:AppThemeServices.textTheme.h15.copyWith(color:AppThemeServices.appColors.hintTextColor)
                ),
              ),
              Divider(color: AppThemeServices.appColors.divider),
              TextField(
                onChanged: (v)=>controller.rgsShareCode=v,
                style: AppThemeServices.textTheme.h15.copyWith(color: Colors.black),
                decoration: InputDecoration(
                    hintText: "请输入邀请码",
                    border: InputBorder.none,
                    hintStyle:AppThemeServices.textTheme.h15.copyWith(color:AppThemeServices.appColors.hintTextColor)
                ),
              ),
              Divider(color: AppThemeServices.appColors.divider),
              const SizedBox(height: 40),
              SizedBox(width: double.infinity,child: ElevatedButton(
                  onPressed:controller.isRgsButtonClick?()=>controller.doRgs():null,
                  style: ElevatedButton.styleFrom(
                      primary: AppThemeServices.appColors.colorPrimary,
                      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(45)),
                      shadowColor: Colors.transparent,
                      fixedSize: const Size(double.infinity, 43)
                  ),
                  child: Text("注册",style: AppThemeServices.textTheme.h15.copyWith(color: Colors.white))))

            ],
          ),
        ))
      ],
    );
  }
}
